home *** CD-ROM | disk | FTP | other *** search
- #ifndef lint
- static RCSid[]="@(#)$Header: decompress.c,v 3.1 86/10/15 08:14:48 pb Rel $"
- #endif lint
-
- /***********************************************************************\
- * *
- * A simple program to expand a Prime file in compressed format *
- * *
- * Copyright 1986, Piete Brooks, Julian Onions & Adrian Pell *
- * pb@cl.cam.ac.uk, jpo@hcig.nott.ac.uk, Adrian.R.Pell@reading.ac.uk *
- * *
- * This program may be copied as long as you don't remove this notice, *
- * try to make any money off of it, or pretend that you wrote it. *
- * *
- \***********************************************************************/
-
- #include <stdio.h>
-
- #define OK 0
- #define WRONG_NUMBER_OF_ARGUMENTS 1
- #define BAD_INPUT_FILE 2
- #define BAD_OUTPUT_FILE 3
-
- #define USAGE "Usage: %s inputfile outputfile\n"
-
- FILE *fopen ();
-
- main (argc, argv)
- int argc;
- char **argv;
- { FILE *input, *output;
-
- /* Check if he has the correct number of arguments or if
- * he has specied a leading '-'. If either give a usage message.
- */
-
- if (argc != 3 || *argv[1] == '-')
- { fprintf (stderr, USAGE, argv[0]);
- exit ((argc != 3) ? WRONG_NUMBER_OF_ARGUMENTS : OK);
- }
-
- if ((input = fopen (argv[1], "r")) == NULL)
- { fprintf (stderr, "Unable to open input file %s\n", argv[1]);
- perror (argv[0]);
- exit (BAD_INPUT_FILE);
- }
-
- if ((output = fopen (argv[2], "o")) == NULL)
- { fprintf (stderr, "Unable to open output file %s\n", argv[2]);
- perror (argv[0]);
- exit (BAD_OUTPUT_FILE);
- }
-
- /* We managed to open the files, now simply read an ascii file and
- * write a binary one, one character at a time.
- */
-
- while(1)
- { register c;
-
- if ((c = fgetc (input)) == EOF)
- { /* Real EOF or error ? */
- if (feof (input)) break;
-
- fprintf (stderr, "Error in reading input file\n");
- perror (argv[0]);
- exit (BAD_INPUT_FILE);
- }
-
- if ((fputc ((char) c, output)) == EOF)
- { fprintf (stderr, "Error in writing output file\n");
- perror (argv[0]);
- exit (BAD_OUTPUT_FILE);
- }
- }
-
- (void) fclose (input);
- (void) fclose (output);
- exit (OK);
- }
-